<?php
class couponModel extends model{
	public $base;
	public function __construct(&$base){
		parent::__construct($base);
		$this->base=$base;
		$this->table="coupon";
	}
	
	public function type_list(){
		return array(
			1=>"全站可用",
			2=>"夜猫店",
			3=>"校园超市",
			4=>"学生街",
		);
	}
	
	public function getByIds($ids){
		if($ids){
			$data=$this->select(array("where"=>" id in("._implode($ids).")"));
			if($data){
				foreach($data as $v){
					$t_d[$v['id']]=$v;
				}
				return $t_d;
			}
		}
	}
	
	public function UseList($userid,$typeid,$money){
		$where=" status=0 AND siteid=".SITEID." AND userid=".$userid;
		$da=M("coupon_user")->select(array("where"=>$where));
		if($da){
			foreach($da as $v){
				$ids[]=$v['coupon_id'];
			}
			$coupons=$this->select(array("where"=>"  id in("._implode($ids).")  AND siteid=".SITEID." AND typeid in("._implode($typeid).") AND lower_money<".$money." "));
			return $coupons;
		}
	}
	
}

?>